﻿var ns = namespace("kaskelot.sp.ui");

ns.adminintegration = function () {
	function init() {
		$(".chzn-select").chosen({ disable_search: true });
		$("#valtyp_chzn").css("width", 175);
		$("#valtyp_chzn .chzn-drop").css("width", 173);
	}

	function doIntegration(method, linkSelector, parameters) {
		var selector = "#integration-toplevel-container";
		$(selector).block();

		if (parameters == undefined) {
			parameters = {};
		}

		$.ajax({
			url: L_Menu_BaseUrl + "/_vti_bin/Kaskelot.SP.Resources/ClientDocumentService.svc/" + method,
			type: "GET",
			data: parameters,
			processData: true,
			cache: false,
			success:
				function (data) {
					$(linkSelector).attr("href", "../../" + data[method + "Result"].Data);
					$(linkSelector).show();
					$(selector).unblock();
				},
			error:
				function (xhr) {
					kaskelot.sp.ui.prompts.showErrorPrompt(xhr.responseText);
					$(selector).unblock();
				}
		});
	}

	function createLISAFil(){
		doIntegration("CreateLISAPersonFil", "#lisa-container > #file-link-person");
	}

	function createSkatteverketFil(){
		doIntegration("CreateSkatteverketFil", "#skatteverket-container > #file-link-skatteverket");
	}

	function createArkivFil() {
		doIntegration("CreateArkivFil", "#earkiv-container > #file-link-arkivinfo", { valtyp: $("#valtyp").val() });
	}

	return {
		init: init,
		createLISAFil: createLISAFil,
		createSkatteverketFil: createSkatteverketFil,
		createArkivFil: createArkivFil
	};
}();